<template>
	<view :class="[isSingle?'mx-3':'']" class="news-list-wrap-item d-flex flex-column border-bottoms  j-sb" style="height: auto;" @tap="skipToNewsDetail">
		<view><image :src="item.thumb" mode="" style="height: 368rpx;width: 690rpx;"></image></view>
		<text style="font-size: 32rpx;line-height: 48upx;" class="multi-row-over">{{ item.title }}</text>
		<view class="d-flex j-sb a-center" style="color: #A3A3A3;">
			<view class="font-24 d-flex a-center">
				<text class="mr-2" style="font-size:12px">{{ item.origin }}</text>
				<text class="mr-2" style="font-size:12px">{{ item.releaseDataDes }}</text>
				<!-- <view class="font-24" v-if="isRecommend">
					<text class="iconfont icon-comment1 mr-1"></text>
					<text>{{item.commentCount}}</text>
				</view> -->
			</view>
			<!-- <image v-if="isRecommend" src="../../static/images/recommend.png" style="width: 50upx;height: 26upx;" mode=""></image> -->
			<!-- <text v-if="isRecommend" class="recommend">推荐</text> -->
		</view>
	</view>
</template>

<script>
export default {
	props: {
		item: {
			type: Object,
			default: () => {
				return {};
			}
		},
		isRecommend:{
			type: Boolean,
			default: false
		},
		isSingle:{
			type: Boolean,
			default: false
		}
	},
	methods:{
		skipToNewsDetail(){
			console.log(this.item);
			const newsId = this.item.contentId;
			const url = this.item.url;
			uni.navigateTo({
				url:'/pages/index/news-detail/news-detail?id=' + newsId + '&link=' + url
			})
			//加入历史记录
			let list = uni.getStorageSync('history')
			list = list ? JSON.parse(list) : [];
			let index = list.findIndex(v=>v.contentId === newsId)
			if(list.length >= 50){
				list.pop()
			}
			if(index === -1){
				 list.unshift(this.item);
			     uni.setStorageSync('history',JSON.stringify(list))
			}else{
				for (var i = 0; i < list.length; i++) {
				            if (list[i].contentId === newsId) {
				                list.splice(i, 1); // 如果数据组存在该元素，则把该元素删除
				                break;
				            }
					}
				list.unshift(this.item);
				uni.setStorageSync('history',JSON.stringify(list))
			}
		}
	}
};
</script>

<style scoped>
.image-list {
	width: 300rpx;
	height: 171rpx;
}
.news-list-wrap-item {
	height: 171rpx;
	padding-top: 10px;
	padding-bottom: 15px;
}
.recommend{
	width: 50upx;
	height: 26upx;
	font-size: 12px;
	color: #005bac;line-height: 12px;
}
</style>
